//
//  CellForFirstDesc.m
//  Movie
//
//  Created by dllo on 16/3/26.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "CellForFirstDesc.h"
#import "MovieModel.h"

@implementation CellForFirstDesc

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createView];
    }
    return self;
}


- (void)createView{
    
    self.contentView.backgroundColor = [UIColor colorWithRed:40 / 255.f green:40 / 255.f blue:40 / 255.f alpha:1];
    
    self.title = [[UILabel alloc] init];
    [self.contentView addSubview:self.title];
    
    self.desc = [[UILabel alloc] init];
    [self.contentView addSubview:self.desc];
}


- (void)layoutSubviews{

    self.title.frame = CGRectMake(15, 5, self.contentView.frame.size.width - 30, 30);
    self.title.textColor = [UIColor whiteColor];
    self.title.font = [UIFont boldSystemFontOfSize:18];
    
    self.desc.frame = CGRectMake(15, 45, self.contentView.frame.size.width - 30, [[self class] heightForLabel:self.desc.text]);
    self.desc.numberOfLines = 0;
    self.desc.font = [UIFont systemFontOfSize:15];
    self.desc.textColor = [UIColor whiteColor];
}

+ (CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 20, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
    
    return rect.size.height + 50;
}

+ (CGFloat)heightForDesc:(MovieModel *)model{

    CGFloat height = [CellForFirstDesc heightForLabel:model.content];
    
    return height;
}


- (void)passModel:(MovieModel *)model{

    self.title.text = model.title;
    self.desc.text = model.content;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
